class Stack < Pan::Component
  def initialize background
    @stack = []
    background.owner = self
    push_layer(background)
  end

  def name
    @name
  end

  def name=(name)
    @name = name
  end

  def push_layer(comp)
    comp.owner = self
    @stack.push(comp)
  end
  def pop_layer()
    @stack.pop if @stack.size > 1
  end
  def top()
    @stack[-1]
  end
  def render_on(html)
    top().render(html)
  end

  def nearest_stack
    puts "nearest_stack: #{self.inspect}"
    return parent.nearest_stack
  end

  def method_missing(sym, *args)
    puts "Stack.method_missing: #{sym}, #{args.join(', ')}"
    @stack.each do |layer|
      layer.send(sym, *args) if layer.respond_to? sym
    end
  end
end
